home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 May / SGI IRIX 6.5 Complementary Applications 2004 May.iso / dist / OpenOffice.idb / usr / OpenOffice / help / en / sbasic.jar / text / sbasic / common / 03020202.xml < prev    next >
Encoding:
Extensible Markup Language  |  2002-01-24  |  3.5 KB  |  52 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <html><head><title>Input# Statement [Runtime]</title><meta name="filename" content="text/sbasic/common/03020202"/><meta name="language" content="en-US"/><help:css-file-link xmlns:help="http://openoffice.org/2000/help"/><!--The CSS style header method for setting styles--><style type="text/css">
  3.  
  4.         p.P1{
  5.                 }
  6.         p.P2{
  7.                 }
  8.         span.T1{
  9.                 font-weight:bold;}
  10.         </style></head><body>
  11.   
  12.   
  13.   <help:to-be-embedded Eid="input" xmlns:help="http://openoffice.org/2000/help">
  14.   <p class="Head1"><help:link Id="66540">Input# Statement [Runtime]</help:link></p>
  15.   <p class="Paragraph">Reads data from an open sequential file.</p>
  16.   </help:to-be-embedded>
  17.   <p class="Paragraph"><span class="T1">Syntax</span>:</p>
  18.   <p class="Paragraph">Input #FileNumber As Integer; var1[, var2[, var3[,...]]] <help:key-word value="Input" tag="kw66540_1" xmlns:help="http://openoffice.org/2000/help"/></p>
  19.   <p class="Paragraph"><span class="T1">Parameter</span>:</p>
  20.   <p class="Paragraph">FileNumber: Number of the file from which data is to be read. The file must have been opened by the Open statement with the key word INPUT.</p>
  21.   <p class="Paragraph">var: A variable to which the values read from the file are assigned. Numeric and string variables are valid.</p>
  22.   <p class="Paragraph">The <span class="T1">Input#</span> statement is used to read numeric values or strings from an open file and assign the data to one or more variables. A numeric variable is read up to the first carriage return (Asc=13), line feed (Asc=10), space, or comma. String variables are read to the first carriage return (Asc=13), line feed (Asc=10), or comma.</p>
  23.   <p class="Paragraph">Data and data types in a file must appear in the same order as the variables passed in var. If you assign non-numeric values to a numeric variable, the variable is assigned the value zero.</p>
  24.   <p class="Paragraph">Since records in the file may be separated by commas, commas cannot be read to a string variable. Quotation marks (") in the file are disregarded as well. If you want to read these characters from the file, use the <span class="T1">Line Input#</span> statement to read pure text files (files containing only printable characters) line by line.</p>
  25.   <p class="Paragraph">If the end of the file is reached while reading a data element, an error occurs and the process is aborted.</p>
  26.   <p class="P2">Example:</p>
  27.   <p class="PropText">Sub ExampleWorkWithAFile</p>
  28.   <p class="PropText">Dim iNumber As Integer</p>
  29.   <p class="PropText">Dim sZeile As String</p>
  30.   <p class="PropText">Dim aFile As String</p>
  31.   <p class="PropText">Dim sMsg as String</p>
  32.   <p class="PropText">aFile = "c:\data.txt"</p>
  33.   <p class="PropText"/>
  34.   <p class="PropText">iNumber = Freefile</p>
  35.   <p class="PropText">Open aFile For Output As #iNumber</p>
  36.   <p class="PropText">Print #iNumber, "This is a line of text"</p>
  37.   <p class="PropText">Print #iNumber, "This is another line of text"</p>
  38.   <p class="PropText">Close #iNumber</p>
  39.   <p class="PropText"/>
  40.   <p class="PropText">iNumber = Freefile</p>
  41.   <p class="PropText">Open aFile For Input As iNumber</p>
  42.   <p class="PropText">While not eof(iNumber)</p>
  43.   <p class="PropText">Line Input #iNumber, sLine</p>
  44.   <p class="PropText">If sLine <>"" then</p>
  45.   <p class="PropText">sMsg = sMsg & sZeile & chr(13)</p>
  46.   <p class="PropText">end if</p>
  47.   <p class="PropText">wend</p>
  48.   <p class="PropText">Close #iNumber</p>
  49.   <p class="PropText">Msgbox sMsg</p>
  50.   <p class="PropText">End Sub</p>
  51.   <p class="PropText"/>
  52.  </body></html>